//
// request.hpp
// ~~~~~~~~~~~
//
#ifndef HTTP_SERVER3_REQUEST_HPP
#define HTTP_SERVER3_REQUEST_HPP

#include <string>
#include <vector>
#include "header.hpp"
#include <boost/asio.hpp>
#include <boost/scoped_array.hpp>
#include <boost/weak_ptr.hpp>
#include "hiredis/hiredis.hpp"



namespace http {
    namespace server3 {

        class connection;

        namespace request_headers
        {
            const std::string connection_header =
                "Connection";
        }
        namespace request_values{
            const std::string keep_alive_value =
                "keep-alive";
            const std::string close_value =
                "close";
        }
        /// A request received from a client.
        struct request
        {

            boost::weak_ptr<connection> connection_weak_ptr_;
            unsigned int connection_id;
            std::string method;
            std::string uri;
            int http_version_major;
            int http_version_minor;
            std::vector<header> headers;
            std::string business_str;

            //Them ip va port de truyen vao cho business
            int port;
            std::string ip;
            void initialize_business_id();
            bool get_header_value(const std::string header_str, std::string& header_value_str);
            void reset();

            void add_header(const std::string &name_, const std::string &value_);
            std::string toStdString()
            {
                   std::string request_str;
                   std::vector<header>::iterator it;
                   request_str.append("URI: ").append(uri).append("\n");
                   request_str.append("Header: \n");
                   for ( it = headers.begin(); it < headers.end(); it++ )
                   {
                           request_str.append(it->name).append("=").append(it->value).append("\n");
                   }
                   return request_str;
            }

        };
    } // namespace server3
} // namespace http

#endif // HTTP_SERVER3_REQUEST_HPP
